home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / management / screenmod / source / screenset.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  4KB  |  152 lines

  1. /*********************************************************************\
  2.  *                         ScreenSet v1.0                            *
  3.  *                                                                   *
  4.  * Written by Syd L. Bolton  ©1991 Legendary Design Technologies Inc.*
  5.  *                                                                   *
  6.  *           Works in conjunction with ScreenMod v1.0                *
  7.  *                                                                   *
  8.  * This program's executable, source code, and documentation are all *
  9.  * Copyright ©1991 Legendary Design Technologies Inc.                *
  10.  *                 25 Frontenac Avenue                               *
  11.  *                 Brantford, Ontario                                *
  12.  *                 CANADA  N3R 3B7                                   *
  13.  *                 (519)-754-4070  (519)-754-4059 FAX                *
  14.  *                                                                   *
  15.  *              This program is freely distributable.                *
  16.  *                                                                   *
  17.  *       Version: 001   Date: May 9, 1991  Time: 00:22:05            *
  18. \*********************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <intuition/intuition.h>
  22. #include <intuition/intuitionbase.h>
  23.  
  24. long *IntuitionBase,*GfxBase;
  25. char string[80],origtitle[80];
  26. int origwidth,origheight;
  27. int leftedge,topedge,width,height,detailpen,blockpen,numcolors;
  28. long colors[32];
  29. long modes;
  30. UWORD cl[32];
  31. struct Screen *Screen;
  32.  
  33. FILE *fp;
  34.  
  35. main(argc,argv)
  36. int argc;
  37. char *argv[];
  38. {
  39. int n,valid;
  40.  
  41. if ((argc != 2) || (argv[1][0]=='?')) {
  42.     printf("ScreenSet v1.0 by Syd L. Bolton ©1991 Legendary Design Technologies Inc.\n");
  43.     printf("Usage: %s filename\n",argv[0]);
  44.     exit(1);
  45.     }
  46.     
  47. fp=fopen(argv[1],"r");
  48.  
  49. if (fp==NULL) {
  50.     puts("Couldn't open file.");
  51.     exit(1);
  52.     }
  53.  
  54. openlibraries();
  55.  
  56. fscanf(fp,"%s",&string);
  57. if(strcmp(string,"SM1")) {
  58.     puts("Not a valid ScreenSet/Mod file!");
  59.     fclose(fp);
  60.     exit(1);
  61.     }
  62. getc(fp);
  63. n=0;
  64. while ((origtitle[n]=getc(fp)) != '\n')
  65.            ++n;
  66. origtitle[n]='\0';
  67. if(!(strcmp(origtitle,"*NN"))) origtitle[0]='\0';  /* it was a blank */
  68. fscanf(fp,"%4d%4d\n",&origwidth,&origheight);
  69.  
  70. valid=lookforscreen();
  71. if (valid) {
  72.     puts("SCREENSET:  Couldn't find screen!");
  73.     fclose(fp);
  74.     closelibraries();
  75.     exit(1);
  76.     }
  77. fscanf(fp,"%4d%4d%4d%4d%2d%2d\n",&leftedge,&topedge,&width,&height,&detailpen,&blockpen);
  78. n=0;
  79. while ((string[n]=getc(fp)) != '\n')
  80.     ++n;
  81. string[n]='\0';
  82. if(!(strcmp(string,"*NN"))) string[0]='\0';  /* it was a blank */
  83. strcpy(Screen->Title,string);
  84. n=0;
  85. while ((string[n]=getc(fp)) != '\n')
  86.     ++n;
  87. string[n]='\0';
  88. if(!(strcmp(string,"*NN"))) string[0]='\0';  /* it was a blank */
  89. strcpy(Screen->DefaultTitle,string);
  90. fscanf(fp,"%6d\n",&modes);
  91. fscanf(fp,"%2d\n",&numcolors);
  92. for (n=0; n<numcolors; n++) {
  93.     fscanf(fp,"%4d\n",&colors[n]);
  94.     cl[n]=colors[n];   /* gotta convert to UWORD for LOADRGB4 */
  95.     }
  96. fclose(fp);
  97. Screen->LeftEdge=leftedge; Screen->TopEdge=topedge;
  98. Screen->Width=width; Screen->Height=height;
  99. Screen->DetailPen=detailpen; Screen->BlockPen=blockpen;
  100. Screen->ViewPort.DxOffset=leftedge; Screen->ViewPort.DyOffset=topedge;
  101. Screen->ViewPort.Modes=modes;
  102. RemakeDisplay();
  103. if (Screen->Flags & SHOWTITLE) ShowTitle(Screen,TRUE); /* show title if supposed to */
  104. LoadRGB4(&Screen->ViewPort,&cl[0],numcolors);
  105. closelibraries();
  106. }
  107.  
  108. lookforscreen()
  109. {
  110. int rv,fallout=0;
  111.  
  112. Screen=IntuitionBase->FirstScreen;
  113. rv=checkvalid();
  114. if (rv==0) return(0);  /* wants to modify front screen */
  115. do {
  116.     Screen=Screen->NextScreen;
  117.     rv=checkvalid();
  118.     if (rv==0) return(0);
  119.     if (Screen==NULL) fallout=1;
  120.     } while (fallout==0);
  121. return(1);
  122. }
  123.  
  124. checkvalid()
  125. {
  126. if (strcmp(origtitle,Screen->DefaultTitle)) return(1);
  127. if (origwidth != Screen->Width) return(2);
  128. if (origheight != Screen->Height) return(3);
  129. return(0);
  130. }
  131.  
  132. openlibraries()
  133. {
  134. if(!(IntuitionBase=OpenLibrary("intuition.library",0L))) {
  135.     puts("Couldn't open Intuition!");
  136.     fclose(fp);
  137.     exit(1);
  138.     }
  139. if(!(GfxBase=OpenLibrary("graphics.library",0L))) {
  140.     puts("Couldn't open graphics!");
  141.     fclose(fp);
  142.     exit(1);
  143.     }
  144. }
  145.  
  146. closelibraries()
  147. {
  148. if (GfxBase) CloseLibrary(GfxBase);
  149. if (IntuitionBase) CloseLibrary(IntuitionBase);
  150. }    
  151.  
  152.